package cn.star.jots.previewSort.controller;

import cn.star.jots.base.response.JsonResult;
import cn.star.jots.previewSort.pojo.dto.PreviewSortQuery;
import cn.star.jots.previewSort.pojo.dto.PreviewSortSaveParam;
import cn.star.jots.previewSort.pojo.vo.PreviewSortVO;
import cn.star.jots.previewSort.service.PreviewSortService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/previewSort")
@Api(tags = "用户端预告片管理")
@Slf4j
public class PreviewSortController {

    @Autowired
    PreviewSortService previewSortService;

    @GetMapping("/select")
    @ApiOperation(value = "查询预告片")
    public JsonResult selectAll(PreviewSortQuery previewSortQuery) {
        log.info("查询预告片:previewSortQuery={}", previewSortQuery);
        List<PreviewSortVO> list = previewSortService.selectAll(previewSortQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存预告片信息")
    public JsonResult save(PreviewSortSaveParam previewSortSaveParam) {
        log.info("保存预告片信息:previewSortSaveParam={}", previewSortSaveParam);
        previewSortService.save(previewSortSaveParam);
        return JsonResult.ok();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除预告片信息")
    public JsonResult delete(@PathVariable Long id) {
        log.info("删除预告片信息:id={}", id);
        previewSortService.delete(id);
        return JsonResult.ok();
    }
}
